package service

import (
	"fmt"
	"time"
)

type TestService struct {
	LogChan chan string
}

func (t *TestService) TestTimer() {
	stopChan := make(chan struct{})
	go t.worker(stopChan)

	time.Sleep(2 * time.Second)
	close(stopChan)

	time.Sleep(1 * time.Second) // Wait for worker to stop
}

func (t *TestService) MakeLog() {
	for i := 0; i < 10; i++ {
		t.LogChan <- fmt.Sprint(i)
		time.Sleep(1 * time.Second)
	}
	//close(t.LogChan)
}

func (t *TestService) worker(stopChan <-chan struct{}) {
	for {
		select {
		case <-stopChan:
			fmt.Println("Stopping worker")
			return
		default:
			fmt.Println("Working...")
			time.Sleep(500 * time.Millisecond)
		}
	}
}
